home *** CD-ROM | disk | FTP | other *** search
- REM This is a fully functioning List Requestor. Like a File Requestor
- REM it's used to display a list of strings from which the user may
- REM select one or more elements while being able to scroll through
- REM the list using either a Prop gadget or Up and Down scroll arrows.
- REM
- REM by Steven D. Kapplin, CIS 70055,1021
- REM June 15, 1990
- REM Written in HiSoft Basic
- REM
- REM Compiles to approximately 8,600 bytes (w/o library).
- REM Example of a list requestor. It sets up a requestor and prop gadget
- REM to scroll a list of items in the text box and allow an item or items to
- REM be selected. The selected items are placed in an array, index%()
- REM which keeps track of the items selected. A counter, ix%, keeps
- REM track of the number of selected items. When the "Done" gadget
- REM is hit, the program then lists the selected items using the index%()
- REM array as an index to the string array, s$().
- REM Strings can be a maximum of 15 characters and will be truncated if
- REM longer and padded with spaces if shorter.
- REM Some of this code is part of a larger library of Basic intuition
- REM subroutines, which has been included in this archive for others to
- REM use. It was derived from Halfhill and Brannon's Advanced Amiga
- REM Basic and modified by me. Several of the routines included in this
- REM listing have been modified from those in the library listings. You
- REM can replace those functions, if you feel the need for the changes.
- REM The code here does not include routines for deleting items from a
- REM list, but that should be simple enough to add. This example only
- REM adds items to the list. If an item is re-clicked, although it is
- REM de-selected, it will still show up in the list because there is no
- REM code for deleting it and collapsing the list. Also there has been
- REM no attempt to sort the list, so items appear in the order selected.
- REM
- REM
-
- REM From Intuits.header
- COMMON SHARED which%,BoxIndex%,MaxLen%,ScrID%,Sheight%
- DIM work%(400),p%(100)
- DIM x1%(51),y1%(51),x2%(51),y2%(51)
- REM Set ScrID% to -1 for WB
- ScrID%=-1
- which%=0 'which% box is selected
- BoxIndex%=1 'How many gadgets
- maxlen%=15 'length of text fields
- REM
-
-
- 'Define number of items in list and items displayed in text box
- 'NumEls% = total number of items in list
- 'ElsDisp% = items displayed at one time
- NumEls%=50 : ElsDisp%=6
-
- 'This sets up a list of items
- 'The items are padded to 12 characters max with spaces
- 'If items larger than 12 characters, then they are truncated
- DIM s$(NumEls%),index%(NumEls%)
- FOR i%=0 to 49
- s$(i%)="String "+STR$(i%)
- IF LEN(s$(i%))>15 THEN s$(i%)=LEFT$(s$(i%),15)
- IF LEN(s$(i%))<15 THEN s$(i%)=s$(i%)+SPACE$(15-LEN(s$(i%)))
- NEXT i%
- '
- '
- 'Some constants
- 'bx% = list box left edge
- 'by% = list box top edge
- 'Bwidth% = list box width
- 'Bheight% = list box height
- 'Ght% = item height in list
- 'PtabOffset% = fudge for PTAB function
- bx%=100 : by%=30 : Bwidth%=122 : Bheight%=60 : Ght%=10 : PtabOffset%=7
- '
- 'Define values for prop gadget, some are relative to list box
- 'px% = propgad left edge
- 'py% = propgad top edge
- 'Pwidth% = propgad width
- 'Pheight% = propgad height
- Pwidth%=10 : Pheight%=Bheight%-20 : px%=bx%+Bwidth%+6 : py%=by%+10
- '
- 'Make text box
- LINE (bx%-2,by%-2)-(bx%+Bwidth%,by%+Bheight%),WINDOW(6)-2,b
- LINE (bx%-6,by%-6)-(bx%+Bwidth%+Pwidth%+16,by%+Bheight%+20),WINDOW(6),b
-
-
- 'Initial display of first ElsDisp% items
- FOR i%=0 TO ElsDisp%-1
- PRINT PTAB(bx%,by%+i%*Ght%+PtabOffset%) : CALL SmallTxGad(SPACE$(13))
- PRINT PTAB(bx%,by%+i%*Ght%+PtabOffset%);s$(l%+i%)
- NEXT i%
-
- 'Make prop gadget
- CALL MakeProp(px%,py%,PWidth%,Pheight%,ElsDisp%,NumEls%)
-
- 'make Up and Down arrow gadgets
- CALL Gadget(px%-2,py%-14,15,11,-1,0)
- CALL Gadget(px%-2,py%+Pheight%+2,15,11,-1,0)
-
- AREA (px%+Pwidth%/2,py%-13)
- AREA STEP (-Pwidth%/2,9)
- AREA STEP (9,0)
- AREAFILL
- AREA (px%,py%+Pheight%+2)
- AREA STEP (Pwidth%/2,9)
- AREA STEP (Pwidth%/2,-9)
- AREAFILL
-
- 'Make Done and Cancel gadgets
- '
- PRINT PTAB(bx%-2,by%+Bheight%+14) : CALL SmallTxBox("Done")
- PRINT PTAB(bx%+Bwidth%-52,by%+Bheight%+14) : CALL SmallTxBox("Cancel")
- '
- 'Main loop
- pos%=py%
- ix%=0
- DO
- CALL WaitBox(gad%)
- SELECT CASE gad%
- CASE 7
- DO WHILE MOUSE(0)=-1
- l%=INT((pos%-py%)/(Pheight%-Sheight%-2)*(NumEls%-ElsDisp%))
- CALL SliderPos(gad%,pos%,1)
- CALL Delay(.05)
- GOSUB DoDisplay
- LOOP
- CASE 8
- CALL FlashRelease(gad%)
- IF l%>0 THEN
- DECR l%
- CALL SliderPos(7,pos%,-1)
- GOSUB DoDisplay
- END IF
- CASE 9
- CALL FlashRelease(gad%)
- IF l%<NumEls%-ElsDisp% THEN
- INCR l%
- CALL SliderPos(7,pos%,0)
- GOSUB DoDisplay
- END IF
- CASE 1 TO ElsDisp%
- CALL FlashRelease(gad%)
- CALL CheckBox(gad%,1)
- INCR ix%
- index%(ix%)=l%+gad%-1
- CASE 10
- CALL FlashRelease(gad%)
- CLS
- IF ix% > 0 THEN
- for i%=1 to ix%
- PRINT s$(index%(i%))
- next i%
- END IF
- END
- CASE 11
- CALL FlashRelease(gad%)
- ix%=0
- CLS
- END
- END SELECT
- LOOP
-
- SUB Delay(t!)
- 't! is amount of time to delay
- '
- p!=TIMER
- WHILE TIMER < (p!+t!)
- WEND
- END SUB
-
- REM From Intuits.SUB
- REM
- REM MakeProp
- SUB MakeProp(Xmin%,Ymin%,PropWidth%,PropHeight%,EleDisplayed%,TotNumEls%)
- 'Make a proportional gadget
- 'Xmin% = Left edge
- 'Ymin% = Top edge
- 'PropWidth% = width of propgad box
- 'PropHeight% = height of propgad box
- 'EleDisplayed% = number of elements displayed at one time
- 'TotNumEls% = total number of elements in list
- '
- SHARED Sheight%,x1%(),y1%(),x2%(),y2%(),BoxIndex%,p%()
- Swidth%=PropWidth%
- Sheight%=EleDisplayed%/TotNumEls%*PropHeight%
- LINE (Xmin%,Ymin%)-(Xmin%+Swidth%,Ymin%+Sheight%),,bf
- GET (Xmin%,Ymin%)-(Xmin%+Swidth%,Ymin%+Sheight%),p%
- LINE (Xmin%-2,Ymin%-2)-(Xmin%+PropWidth%+2,Ymin%+PropHeight%),,b
- x1%(BoxIndex%)=Xmin% : y1%(BoxIndex%)=Ymin%
- x2%(BoxIndex%)=Xmin%+PropWidth% : y2%(BoxIndex%)=Ymin%+PropHeight%
- BoxIndex%=BoxIndex%+1
- END SUB
-
- REM SliderPos
- SUB SliderPos(i%,NewPos%,fl%)
- 'Positions proportional gadget slider
- 'i% = gadget ID number
- 'NewPos% = input/output = position of slider
- 'You can get the index value associated with the change in slider position
- ' by using the following line:
- ' l%=INT((pos%-y%)/(Pheight%-Sheight%-2)*(TotNumEls%-NumElsDisplayed%))
- ' which is placed in the intuition message loop.
- '
- SHARED Sheight%,x1%(),y1%(),x2%(),y2%(),p%()
- PUT (x1%(i%),NewPos%),p%
- IF fl%=1 THEN
- NewPos%=MOUSE(2)-1
- ELSEIF fl%=0 THEN
- INCR NewPos%
- ELSEIF fl%=-1 THEN
- DECR NewPos%
- END IF
- IF NewPos% > y2%(i%)-Sheight%-2 THEN NewPos%=y2%(i%)-Sheight%-2
- IF Newpos% < y1%(i%) THEN NewPos%=y1%(i%)
- PUT (x1%(i%),Newpos%),p%
- END SUB
-
- REM SmallTxBox
- 'Gadget box with text in msg$
- SUB SmallTxBox(msg$) STATIC
- SHARED x1%(),y1%(),x2%(),y2%()
- SHARED BoxIndex%
- x1%=WINDOW(4) : y1%=WINDOW(5)-8
- PRINT " ";msg$;" ";
- x2%=WINDOW(4) : y2%=y1%+11
- CALL Box(BoxIndex%,x1%,y1%,x2%,y2%,-1)
- BoxIndex%=BoxIndex%+1
- PRINT SPC(1);
- END SUB
-
- REM SmallTxGad
- 'Text gadget without a box
- SUB SmallTxGad(msg$) STATIC
- SHARED x1%(),y1%(),x2%(),y2%()
- SHARED BoxIndex%
- x1%=WINDOW(4) : y1%=WINDOW(5)-7
- PRINT " ";msg$;" ";
- x2%=WINDOW(4) : y2%=y1%+10
- CALL NoBoxGad(BoxIndex%,x1%,y1%,x2%,y2%)
- BoxIndex%=BoxIndex%+1
- PRINT SPC(1);
- END SUB
-
- REM Gadget
- 'Plain gadget
- SUB Gadget(x%,y%,wid%,ht%,bflag%,shflag%) STATIC
- 'x%=left edge
- 'y%=top edge
- 'wid%=width
- 'ht%=height
- 'if blfag%=0 no box, if=-1 then box
- 'shflag%=0 no shadow, -1 for shadow
- SHARED x1%(),y1%(),x2%(),y2%()
- SHARED BoxIndex%
- IF bflag%=-1 THEN
- CALL Box(BoxIndex%,x%,y%,x%+wid%,y%+ht%,shflag%)
- ELSE
- CALL NoBoxGad(BoxIndex%,x%,y%,x%+wid%,y%+ht%)
- END IF
- BoxIndex%=BoxIndex%+1
- END SUB
-
- REM Box
- SUB Box(i%,x1%,y1%,x2%,y2%,f%) STATIC
- 'Draw and store a box (i) whose corner
- 'coords are (x1,y1)-(x2,y2)
- 'Can be used to change a box's coords
- 'f% is flag: 0=shadow, -1=no shadow
- SHARED x1%(),y1%(),x2%(),y2%()
- IF x2%<x1% THEN SWAP x1%,x2%
- IF f%=-1 THEN
- LINE (x1%,y1%)-(x2%,y2%),1-(WINDOW(6)>1),b
- END IF
- LINE (x1%,y1%)-(x2%-1,y2%-1),2-(WINDOW(6)>1),b
- x1%(i%)=x1% : y1%(i%)=y1% : x2%(i%)=x2% : y2%(i%)=y2%
- END SUB
-
- REM WaitBox
- SUB WaitBox(which%) STATIC
- 'Wait for a box to be selected
- 'return box number in (which%)
- which%=0
- WHILE which%=0
- SLEEP
- CALL WhichBox(which%)
- WEND
- EXIT SUB
- END SUB
-
- REM WhichBox
- SUB WhichBox(which%) STATIC
- 'See if a box is selected,
- 'otherwise (which%)=0
- 'Used to poll for box selection
- SHARED x1%(),y1%(),x2%(),y2%(),BoxIndex%
- IF MOUSE(0)=0 THEN EXIT SUB
- x%=MOUSE(1) : y%=MOUSE(2) : i%=1
- WHILE i%<BoxIndex% AND NOT (x%>x1%(i%) AND x%<x2%(i%) AND y%>y1%(i%) AND y%<y2%(i%))
- INCR i%
- WEND
- which%=i%
- IF i%=BoxIndex% THEN which%=0
- END SUB
-
- REM CheckBox
- 'Checks a box when selected. Actually, changes box color and
- 'wipes string
- SUB CheckBox(i%,flag%) STATIC
- 'Check a box
- 'Pass variable (flag)
- 'for on/off (-1/0)
- SHARED x1%(),y1%(),x2%(),y2%()
- x1%=x1%(i%) : y1%=y1%(i%)
- x2%=x2%(i%) : y2%=y2%(i%)-1
- COLOR ,,2
- LINE (x1%+1,y1%+1)-(x2%-1,y2%-1),WINDOW(6)*-(flag%<>0),bf
- COLOR ,,1
- END SUB
-
- REM FlashRelease
- SUB FlashRelease(which%) STATIC
- 'Flashes button (which%), waits for
- 'release of mouse button
- 'if mouse moved during release,
- 'global variable RelVerify is set to null,
- 'else is -1 (true).
- SHARED x1%(),y1%(),x2%(),y2%(),work%()
- SHARED RelVerify%
- 'These two lines flash the box
- GET (x1%(which%),y1%(which%))-(x2%(which%),y2%(which%)),work%
- PUT (x1%(which%),y1%(which%)),work%,PRESET
- ix%=MOUSE(1) : iy%=MOUSE(2) : RelVerify%=-1
- WHILE MOUSE(0)<>0
- IF MOUSE(1)<>ix% OR MOUSE(2)<>iy% THEN RelVerify%=0
- WEND
- 'This line restores the box
- PUT (x1%(which%),y1%(which%)),work%,PSET
- END SUB
-
- REM NoBoxGad
- SUB NoBoxGad(i%,x1%,y1%,x2%,y2%) STATIC
- 'Same as Box(), but doesn't draw a box
- SHARED x1%(),y1%(),x2%(),y2%()
- IF x2%<x1% THEN SWAP x1%,x2%
- x1%(i%)=x1% : y1%(i%)=y1% : x2%(i%)=x2% : y2%(i%)=y2%
- END SUB
- REM End of Intuits.SUB stuff
- REM
-
- DoDisplay:
- FOR i%=0 TO ElsDisp%-1
- PRINT PTAB(bx%,by%+Ght%*i%+PtabOffset%);s$(l%+i%)
- NEXT i%
- FOR i%=1 TO ElsDisp%
- FOR j%=1 TO ix%
- IF index%(j%)-l%+1=i% THEN
- CALL CheckBox(i%,1)
- END IF
- NEXT j%
- NEXT i%
- RETURN
-